The present invention relates generally to improving execution performance of computer programs. More specifically, the present invention relates to converting an implicitly multi-threaded program source code of work-items to an explicitly single-threaded program source code of a work-group for use in, for example, a thread-poor computing environment. In one embodiment of the invention, the computer programs are written in Open Computing Language (OpenCL).
There is a natural mapping of the OpenCL computing units onto the graphical processing units (GPUs). A work-group is mapped onto a thread block on GPU, and the work-items are mapped to the threads within the thread block. There is also hardware support for fast scheduling and synchronizing threads within the thread block.
However, on other accelerators that do not have abundant number of hardware threads and fast threads switching mechanism, mapping work-group with multiple work-items is not straight-forward. Examples of such systems are CELL Broadband Engine and multi-core CPUs. CELL SPE can only run one hardware thread at a time, which each core in today's multi-core CPUs can run 2 to 8 SMT threads. To run OpenCL program on such accelerators, a programmer typically has to either limit the number of work-items in each work-group, or an OpenCL implementation has to provide support for accommodating multiple work-items.
One way of supporting multiple work-items of a work-group in a thread-poor environment is to implement a virtual threading mechanism. In such a mechanism, each work-item is mapped to a virtual thread that can be mapped to a hardware thread and virtual threads take turns to be scheduled and executed. However, this mechanism incurs a significant overhead in thread switching for architectures with abundant registers such as CELL SPE, since it relies on either traditional thread switching mechanism in the operating system or the corresponding software emulation, especially when compared to the fast thread switching support in GPU hardware.